package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.role.BatchEnableRoleRequest;
import com.mes.cloud.api.dto.request.role.SysRoleEnablePageListRequest;
import com.mes.cloud.api.dto.request.role.SysRolePageListRequest;
import com.mes.cloud.api.dto.request.role.SysRoleRequest;
import com.mes.cloud.api.dto.response.role.SysRoleDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wxm
 * @version 2019-08-01 15:33:26
 * @email xiaomin.wu1@pactera.com
 */
@Api(tags = "角色表", value = "角色表接口")
@RestController
@RequestMapping(value = "/sysRole")
public class SysRoleController  {

    private SysRoleService sysRoleService;

    @Autowired
    public SysRoleController(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    /**
     * 功能: 角色表分页查询
     *
     * @param sysRolePageListRequest
     * @return JsonResult<CommPager<SysRoleDto>>
     */
    @ApiOperation(value = "角色表分页查询", notes = "角色表分页查询")
    @PostMapping(value = "/pageList")
    public JsonResult<CommPager<SysRoleDto>> pageList(@Valid @RequestBody SysRolePageListRequest sysRolePageListRequest) {
        return sysRoleService.pageList(sysRolePageListRequest);
    }

    /**
     * 功能: 角色表分页查询未禁用
     *
     * @param sysRoleEnablePageListRequest
     * @return JsonResult<CommPager<SysRoleDto>>
     */
    @ApiOperation(value = "角色表分页查询未禁用", notes = "角色表分页查询未禁用")
    @PostMapping(value = "/enablePageList")
    public JsonResult<CommPager<SysRoleDto>> enablePageList(@Valid @RequestBody SysRoleEnablePageListRequest sysRoleEnablePageListRequest) {
        return sysRoleService.enablePageList(sysRoleEnablePageListRequest);
    }


    /**
     * 功能: 角色表新增
     *
     * @param sysRoleRequest
     * @return JsonResult
     */
    @ApiOperation(value = "角色表新增", notes = "角色表新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody SysRoleRequest sysRoleRequest) {
        return sysRoleService.insert(sysRoleRequest);
    }

    /**
     * 功能: 角色表修改
     *
     * @param sysRoleRequest
     * @return JsonResult
     */
    @ApiOperation(value = "角色表修改", notes = "角色表修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody SysRoleRequest sysRoleRequest) {
        return sysRoleService.update(sysRoleRequest);

    }

    /**
     * 功能: 批量禁用启用
     *
     * @param batchEnableRoleRequest
     * @return JsonResult
     */
    @ApiOperation(value = "批量禁用启用", notes = "批量禁用启用")
    @PostMapping(value = "/batchEnableFlag")
    public JsonResult batchEnableFlag(@Valid @RequestBody BatchEnableRoleRequest batchEnableRoleRequest) {
        return sysRoleService.batchEnableFlag(batchEnableRoleRequest);
    }

    /**
     * 功能: 角色表删除
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "角色表删除", notes = "角色表删除")
    @ApiImplicitParam(paramType = "Long", name = "id", value = "角色表主键", required = true)
    @GetMapping(value = "delete/{id}")
    public JsonResult delete(@NotEmpty(message = "id不能为空") @PathVariable String id) {
        return sysRoleService.delete(id);

    }

    /**
     * 功能: 角色表查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "角色表查看详情", notes = "角色表查看详情")
    @ApiImplicitParam(paramType = "Long", name = "id", value = "角色表主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<SysRoleDto> get(@NotEmpty(message = "id不能为空") @PathVariable String id) {
        return sysRoleService.get(id);
    }

    /**
     * 功能: 角色表禁用启用
     *
     * @param id
     * @param enableFlag
     * @return JsonResult
     */
    @ApiOperation(value = "角色表禁用启用", notes = "角色表禁用启用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true),
            @ApiImplicitParam(name = "enableFlag", value = "状态", required = true),
    })
    @GetMapping(value = "/updateEnableFlag/{id}/{enableFlag}")
    public JsonResult updateEnableFlag(@NotEmpty(message = "id不能为空") @PathVariable String id, @NotEmpty(message = "enableFlag不能为空") @PathVariable String enableFlag) {
        return sysRoleService.updateEnableFlag(id, enableFlag);
    }
}
